/**
 *
 */
package com.newer.controller.index;

import com.newer.dao.bean.sys.User;
import net.sf.json.JSONArray;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * 默认页Controller
 *
 * @author 寻添俊
 * 2017年10月31日-下午1:14:59
 */
@Controller
public class IndexController {

    /**
     * 默认页面
     *
     * @return
     */
    @RequestMapping(value = "index.htm")
    public String index() {
        // 判断用户角色以及用户是否完善信息
        return "index";
    }

    /**
     * 默认页面
     *
     * @return
     */
    @RequestMapping(value = "menu.htm")
    @ResponseBody
    public String menu() {
        Subject subject = SecurityUtils.getSubject();
        User user = (User) subject.getPrincipal();
        if (user == null) {
            return "redirect:login.htm";
        }
        return JSONArray.fromObject(user.getMenus()).toString();
    }

    /**
     * 403无权限页面
     *
     * @return
     */
    @RequestMapping(value = "403.htm")
    public String unauthorized() {
        // 判断用户角色以及用户是否完善信息
        return "403";
    }
}
